package Demo1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 34255
 * Date: 2024-07-09
 * Time: 16:30
 */
public class Operate {
    ArrayList<Card> cards = new ArrayList<Card>(52);
    public void buyCard(){//买到 52 张不同的牌，除去大小王
        String[] flowerDecors = {"♥","♠","♣","♦"};
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < flowerDecors.length; j++) {
                cards.add(new Card(flowerDecors[j] + "",i + ""));
            }
        }
    }

    public void swap(int i,int j){//交换牌
//        Card tmp = cards[i];
//        cards[i] = cards[j];
//        cards[j] = tmp;
        Card tmp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,tmp);
    }
    public void shuffle(){//随机洗牌
        for (int i = cards.size() - 1; i >=1 ; i--) {
            Random random = new Random();
            int randomness = random.nextInt(i);
            swap(i,randomness);
        }
    }
    public void Licensing(List<List<Card>> person){//发牌
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card temp = cards.remove(0);
                person.get(j).add(temp);
            }
        }
    }
}
